import 'package:flutter/material.dart';

import '../../config/public_color.dart';

/// FileName public_radio
///
/// @Author lax
/// @Date 2023/11/4
///
/// @Description

class PublicRadio extends StatelessWidget {
  static Color? defaultEnableColor;

  static Color? defaultUnableColor;

  final bool? value;

  final bool? enable;

  final double? size;

  late final Color? enableColor;

  late final Color? unableColor;

  final EdgeInsets? padding;

  final String? title;

  late final TextStyle? titleStyle;

  final Widget? separator;

  PublicRadio({
    super.key,
    this.value = false,
    this.enable = true,
    this.size = 16,
    Color? enableColor,
    Color? unableColor,
    this.padding,
    this.title,
    TextStyle? titleStyle,
    this.separator = const SizedBox(width: 4),
  }) {
    this.enableColor = enableColor ?? defaultEnableColor ?? PublicColor.primary;
    this.unableColor = unableColor ?? defaultUnableColor ?? PublicColor.border;
    this.titleStyle = titleStyle ??
        TextStyle(
            fontSize: 14,
            fontWeight: FontWeight.normal,
            color: PublicColor.darkText);
  }

  @override
  Widget build(BuildContext context) {
    if (title != null) {
      return Row(
        children: [
          radio(),
          separator ?? const SizedBox(),
          Text(title ?? '', style: titleStyle),
        ],
      );
    }
    if (padding != null) {
      return Container(
        padding: padding,
        color: Colors.transparent,
        child: radio(),
      );
    }
    return radio();
  }

  Widget radio() {
    return Icon(
      value == true
          ? Icons.radio_button_checked_outlined
          : Icons.radio_button_off_outlined,
      size: size,
      color: (value == true && enable == true) ? enableColor : unableColor,
    );
  }
}
